// ============================== 导入依赖 ============================== //

import API from './API'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 单项 —————————————————————————————— //

  async remoteOne({ state: { one, DICT } }) {
    if (!one.id) return {}

    const obj = await API.getOne(one, '查询设备详情')
    return transOne(obj, DICT)
  },
}

// ============================== 转换方法 ============================== //

export const transOne = (obj, { FIELD }) => {
  obj.dataList = FIELD.map((item) => ({
    name: item[0],
    value: obj[item[1]],
    unit: item[2],
  }))

  obj.alarmStatus = obj.alarmStatus || 1
  obj.deviceStatus = obj.deviceStatus || 2

  return obj
}
